// ignore_for_file: file_names

import 'dart:math';

import 'package:flutter/material.dart';

class StateDemo extends StatelessWidget {
  const StateDemo(
      {super.key,
      this.title = '',
      this.content = '',
      this.textCol = Colors.black,
      this.textSize = 0});

  final String title;
  final String content;
  final Color textCol;
  final double textSize;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
          toolbarHeight: 100,
          title: Center(
            child: Text(
              '$title ',
              style: const TextStyle(color: Colors.white, fontSize: 50),
            ),
          ),
        ),
        body: MyStateWidget(),
      ),
    );
  }
}

// 1. 继承自StatefulWidget
class MyStateWidget extends StatefulWidget {
  const MyStateWidget({super.key});

  @override
  State<MyStateWidget> createState() => _MyStateWidgetState();
}

// 2. 继承自 State 并传入上一步的类，重写 build 实现 结构
class _MyStateWidgetState extends State<MyStateWidget> {
  int num = 0;
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          ElevatedButton(
              onPressed: () {
                setState(() {
                  if (num > 0) num--;
                });
              },
              child: const Text('递减')),
          Text('$num'),
          ElevatedButton(
              onPressed: () {
                setState(() {
                  num++;
                });
              },
              child: const Text('递增')),
          ElevatedButton(
              onPressed: () {
                setState(() {
                  num = 0;
                });
              },
              child: const Text('归零'))
        ],
      ),
    );
  }
}
